﻿using System;
using System.ComponentModel;
using GenericsFramework.BusinessRules;

namespace BusinessRulesTestApp
{
	class Program
	{
		private static MyClass test;

		static Program()
		{
			test = new MyClass();
			test.PropertyChanged += test_PropertyChanged;
		}

		static void test_PropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			var t = sender as MyClass;

			if (t == null) return;
			
			Console.WriteLine(new MyRules().Validate(t) ? "MyClass is valid" : "MyClass is not valid");
		}

		static void Main(string[] args)
		{
			test.Name = "Tom";
			test.Name = "Bob";
			Console.ReadKey();
		}
	}

	public class MyRules : AbstractRuleBuilder<MyClass>
	{
		protected override void Define()
		{
			Rules(
					Check(r => r.Name.Is("Bob"))
				);
		}
	}
	public class MyClass : INotifyPropertyChanged
	{
		private string _name;
		public string Name
		{
			get { return _name; }
			set 
			{
				_name = value;
				PropertyChanged(this, new PropertyChangedEventArgs("Name"));
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;
	}
}
